<template>
	<view class="page">
		<u-navbar :placeholder="true" title="小区" @leftClick="$utils.back()" border />
		<view class="body">
			<z-paging ref="paging" style="height: 100%;" :fixed="false" v-model="data" @query="query"
				:default-page-no="1" :default-page-size="10">
				<view v-for="item in data" :key="item.id" class="districtItem viewWidth">
					<u--image :src="item.cover" :fade="false" width="200rpx" height="200rpx" radius='10rpx'></u--image>
					<view class="districtContent">
						<view>
							<u--text lines='1' size='32rpx' :text='item.name' />
						</view>
						<view style="flex: 1;margin: 20rpx 0;">
							<u--text lines='1' color='#bbb' size='24rpx' prefixIcon="map" :text='item.address' />
						</view>
					</view>
				</view>
			</z-paging>
		</view>
		<view class="viewWidth">
			<u-button text="没有所在小区,去创建" @click='jump'></u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data: []
			}
		},
		methods: {
			query(page, size) {
				const {
					latitude,
					longitude
				} = uni.getStorageSync('location')
				let obj = {
					latitude,
					longitude
				}
				this.$api.District.Nearby(obj).then(res => {
					this.$refs.paging.completeByNoMore(res.data.districts, true)
				})
			},
			jump(){
				this.$utils.navigateTo({
					url:'/District/Add'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		height: 100vh;
		padding-bottom: calc(constant(safe-area-inset-bottom) + 10rpx);
		/* 兼容 iOS 设备 */
		padding-bottom: calc(env(safe-area-inset-bottom) + 10rpx);
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		background-color: #f5f5f5;
	}

	.body {
		flex: 1;
		margin-top: 20rpx;
	}

	.districtItem {
		width: calc(100vw - 40rpx);
		display: flex;
		padding: 20rpx;
		border-radius: 8rpx;
		background-color: #fff;
		box-shadow: 0 0 10rpx #bbb;
		margin: 0 auto 20rpx;
		box-sizing: border-box;
	}

	.districtContent {
		flex: 1;
		margin-left: 10rpx;
		display: flex;
		flex-direction: column;
	}
	
</style>